﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.Web;

namespace MethodWorx.CMS.TemplateLanguage.Parsers
{
    public class PageParentParser : IParser, IMetaParser
    {
        #region IParser Members

        public string[] Parameters { get { return new string[] { }; } }

        public object Parse(CmsRequestContext context, IEnumerable<object> stack, Dictionary<string, object> parameters)
        {
            var page = stack.OfType<MethodWorx.CMS.Content.Page>().FirstOrDefault();
            if (page == null)
                throw new Exception("No page on the stack");

            //
            //  ok, return the pages
            return page.Parent;
        }

        public string Name
        {
            get { return "parent"; }
        }

        public string Namespace
        {
            get { return "page";  }
        }

        #endregion

        public string GetDescription()
        {
            return "Set the parent page as the current template content";
        }

        public ParserMetaParameter[] GetParameters(Stack<object> stack, ParserMetaParameter[] parameters)
        {
            return parameters;
        }
    }
}
